// var i;
// var $eventManager = require("./EventManager");
// var $resKeeper = require("./ResKeeper");
// var $evenType = require("./EvenType");
// var $gameGlobalVariable = require("./GameGlobalVariable");
// var $buffMag = require("./BuffMag");
// var $uI_MosterLogic = require("./UI_MosterLogic");
// var $uI_BulletBomb = require("./UI_BulletBomb");
// var f = cc._decorator;
// var g = f.ccclass;
// var _ = (f.property, f.inspector);
// var y = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.offtime = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onCollisionEnter = function (e, t) {
//         if (new Date().getTime() - this.offtime >= 100) {
//             $gameGlobalVariable.GameGlobalVariable.playHitBomb1();
//             this.offtime = new Date().getTime();
//             var o = t.node.parent.getComponent($uI_BulletBomb.default);
//             o.getNowMosterNode().forEach(function (e) {
//                 var t = e.getComponent($uI_MosterLogic.default);
//                 $buffMag.BuffMgr.mosterBeHit(t, o.attackfang);
//                 t.beAttack(o);
//                 var n = $buffMag.BuffMgr.getLanGuaErwai(o.attackfang);
//                 if (n) {
//                     var i = t.xueliang * (n.value[0] / 100);
//                     t.fujiaAttack(i, 5, o);
//                 }
//             });
//             var n = e.node.getComponent($uI_MosterLogic.default);
//             $buffMag.BuffMgr.addMosterBombCount(n);
//             o.hideBullet();
//             $eventManager.EventMgr.dispatchEvent(
//                 $evenType.EVENT_TYPE.Game_Add_BaoZha,
//                 o.node.getPosition(),
//                 1,
//                 o.getBombFanWei()
//             );
//         }
//     };
//     t.prototype.onMyCollisionEntyer = function (e) {
//         if (new Date().getTime() - this.offtime >= 100) {
//             $gameGlobalVariable.GameGlobalVariable.playHitBomb1();
//             this.offtime = new Date().getTime();
//             var t = this.node.parent.getComponent($uI_BulletBomb.default);
//             t.getNowMosterNode().forEach(function (e) {
//                 var o = e.getComponent($uI_MosterLogic.default);
//                 $buffMag.BuffMgr.mosterBeHit(o, t.attackfang);
//                 o.beAttack(t);
//                 var n = $buffMag.BuffMgr.getLanGuaErwai(t.attackfang);
//                 if (n) {
//                     var i = o.xueliang * (n.value[0] / 100);
//                     o.fujiaAttack(i, 5, t);
//                 }
//             });
//             var o = e.getComponent($uI_MosterLogic.default);
//             $buffMag.BuffMgr.addMosterBombCount(o);
//             t.hideBullet();
//             $eventManager.EventMgr.dispatchEvent(
//                 $evenType.EVENT_TYPE.Game_Add_BaoZha,
//                 t.node.getPosition(),
//                 1,
//                 t.getBombFanWei()
//             );
//         }
//     };
//     return __decorate([g], t);
// })($resKeeper.default);
// exports.default = y;

// import { EventMgrInstance } from "./EventManager";
// import ResKeeper from "./ResKeeper";
// import { EVENT_TYPE } from "./EvenType";
// import { GameGlobalVariable } from "./GameGlobalVariable";
// import { BuffMgr } from "./BuffMag";
// import UI_MosterLogic from "./UI_MosterLogic";
// import UI_BulletBomb from "./UI_BulletBomb";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名：CollisionHandler
//  * 处理碰撞逻辑的类
//  */
// @ccclass
// class UI_BulletBombCollider extends ResKeeper {
//     private offtime: number = 0;

//     /**
//      * 建议方法名：handleCollisionEnter
//      * 处理碰撞进入事件
//      * @param other 碰撞的其他对象
//      * @param self 碰撞的自身对象
//      */
//     onCollisionEnter(other: cc.Collider, self: cc.Collider): void {
//         const currentTime = new Date().getTime();
//         if (currentTime - this.offtime >= 100) {
//             GameGlobalVariable.playHitBomb1();
//             this.offtime = currentTime;

//             const bulletBomb = self.node.parent.getComponent(UI_BulletBomb);
//             bulletBomb.getNowMosterNode().forEach((monsterNode: cc.Node) => {
//                 const monsterLogic = monsterNode.getComponent(UI_MosterLogic);
//                 BuffMgr.mosterBeHit(monsterLogic, bulletBomb.attackfang);
//                 monsterLogic.beAttack(bulletBomb);

//                 const buff = BuffMgr.getLanGuaErwai(bulletBomb.attackfang);
//                 if (buff) {
//                     const additionalDamage = monsterLogic.xueliang * (buff.value[0] / 100);
//                     monsterLogic.fujiaAttack(additionalDamage, 5, bulletBomb);
//                 }
//             });

//             const monsterLogic = other.node.getComponent(UI_MosterLogic);
//             BuffMgr.addMosterBombCount(monsterLogic);
//             bulletBomb.hideBullet();

//             EventMgrInstance.dispatchEvent(
//                 EVENT_TYPE.Game_Add_BaoZha,
//                 bulletBomb.node.getPosition(),
//                 1,
//                 bulletBomb.getBombFanWei()
//             );
//         }
//     }

//     /**
//      * 建议方法名：handleMyCollisionEnter
//      * 处理自定义碰撞进入事件
//      * @param other 碰撞的其他对象
//      */
//     onMyCollisionEnter(other: cc.Node): void {
//         const currentTime = new Date().getTime();
//         if (currentTime - this.offtime >= 100) {
//             GameGlobalVariable.playHitBomb1();
//             this.offtime = currentTime;

//             const bulletBomb = this.node.parent.getComponent(UI_BulletBomb);
//             bulletBomb.getNowMosterNode().forEach((monsterNode: cc.Node) => {
//                 const monsterLogic = monsterNode.getComponent(UI_MosterLogic);
//                 BuffMgr.mosterBeHit(monsterLogic, bulletBomb.attackfang);
//                 monsterLogic.beAttack(bulletBomb);

//                 const buff = BuffMgr.getLanGuaErwai(bulletBomb.attackfang);
//                 if (buff) {
//                     const additionalDamage = monsterLogic.xueliang * (buff.value[0] / 100);
//                     monsterLogic.fujiaAttack(additionalDamage, 5, bulletBomb);
//                 }
//             });

//             const monsterLogic = other.getComponent(UI_MosterLogic);
//             BuffMgr.addMosterBombCount(monsterLogic);
//             bulletBomb.hideBullet();

//             EventMgrInstance.dispatchEvent(
//                 EVENT_TYPE.Game_Add_BaoZha,
//                 bulletBomb.node.getPosition(),
//                 1,
//                 bulletBomb.getBombFanWei()
//             );
//         }
//     }
// }

// export default UI_BulletBombCollider;

import { EventMgrInstance } from "./EventManager";
import ResKeeper from "./ResKeeper";
import { EVENT_TYPE } from "./EvenType";
import { GameGlobalVariable } from "./GameGlobalVariable";
import { BuffMgr } from "./BuffMag";
import ViewMosterLogic from "./UI_MosterLogic";
import ViewBulletBomb from "./UI_BulletBomb";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：CollisionHandler
 * 处理碰撞逻辑的类
 */
@ccclass
class ViewBulletBombCollider extends ResKeeper {

    /**
     * 最后一次碰撞处理时间
     */
    private lastCollisionTime: number = 0;

    /**
     * 建议方法名：handleCollisionEnter
     * 处理碰撞进入事件
     * @param colliderOther 碰撞的其他对象
     * @param colliderSelf 碰撞的自身对象
     */
    onCollisionEnter(colliderOther: cc.Collider, colliderSelf: cc.Collider): void {
        const currentTimestamp = new Date().getTime();
        if (currentTimestamp - this.lastCollisionTime >= 100) {
            GameGlobalVariable.playBomb1SoundEffect();
            this.lastCollisionTime = currentTimestamp;

            const bulletBombComponent = colliderSelf.node.parent.getComponent(ViewBulletBomb);
            bulletBombComponent.getCurrentMonsterNodes().forEach((monsterNode: cc.Node) => {
                const monsterLogicComponent = monsterNode.getComponent(ViewMosterLogic);
                BuffMgr.monsterHit(monsterLogicComponent, bulletBombComponent.attackfang);
                monsterLogicComponent.receiveAttack(bulletBombComponent);

                const activeBuff = BuffMgr.getBlueMelonExtraBuff(bulletBombComponent.attackfang);
                if (activeBuff) {
                    const extraDamage = monsterLogicComponent.xueliang * (activeBuff.value[0] / 100);
                    monsterLogicComponent.applyAdditionalAttack(extraDamage, 5, bulletBombComponent);
                }
            });

            const monsterLogicComponent = colliderOther.node.getComponent(ViewMosterLogic);
            BuffMgr.addMosterBombCount(monsterLogicComponent);
            bulletBombComponent.hideBullet();

            EventMgrInstance.emitEvent(
                EVENT_TYPE.Game_Add_BaoZha,
                bulletBombComponent.node.getPosition(),
                1,
                bulletBombComponent.getExplosionRange()
            );
        }
    }

    /**
     * 建议方法名：handleMyCollisionEnter
     * 处理自定义碰撞进入事件
     * @param colliderOther 碰撞的其他对象
     */
    handleMyCollisionEnter(colliderOther: cc.Node): void {
        const currentTimestamp = new Date().getTime();
        if (currentTimestamp - this.lastCollisionTime >= 100) {
            GameGlobalVariable.playBomb1SoundEffect();
            this.lastCollisionTime = currentTimestamp;

            const bulletBombComponent = this.node.parent.getComponent(ViewBulletBomb);
            bulletBombComponent.getCurrentMonsterNodes().forEach((monsterNode: cc.Node) => {
                const monsterLogicComponent = monsterNode.getComponent(ViewMosterLogic);
                BuffMgr.monsterHit(monsterLogicComponent, bulletBombComponent.attackfang);
                monsterLogicComponent.receiveAttack(bulletBombComponent);

                const activeBuff = BuffMgr.getBlueMelonExtraBuff(bulletBombComponent.attackfang);
                if (activeBuff) {
                    const extraDamage = monsterLogicComponent.xueliang * (activeBuff.value[0] / 100);
                    monsterLogicComponent.applyAdditionalAttack(extraDamage, 5, bulletBombComponent);
                }
            });

            const monsterLogicComponent = colliderOther.getComponent(ViewMosterLogic);
            BuffMgr.addMosterBombCount(monsterLogicComponent);
            bulletBombComponent.hideBullet();

            EventMgrInstance.emitEvent(
                EVENT_TYPE.Game_Add_BaoZha,
                bulletBombComponent.node.getPosition(),
                1,
                bulletBombComponent.getExplosionRange()
            );
        }
    }
}

export default ViewBulletBombCollider;